# @Time    : 2018/5/30 19:37
# @Author  : Jame
from db import db_handler

class BaseClass:


    @classmethod
    def select(cls,name):
        return db_handler.select(name,cls.__name__.lower())

    #对象的绑定方法
    def save(self):
        db_handler.save(self)

    #所有用户修改自己的密码
    def modify_password(self,passwod):
        self.password=passwod
        self.save()

class Admin(BaseClass):

    def register(self,name,password):
        self.name = name
        self.password = password
        self.save()

    def create_school(self,school_name,address):
        school = School(school_name,address)
        school.save()


    def create_teacher(self,teacher_name,password,school_name):
        teacher = Teacher(teacher_name, password)
        teacher.school_list.append(school_name)
        teacher.save()


    def create_course(self,course_name,cyclical,price,school_name):
        '''
        课程名，周期，价格
        :param course_name:
        :param cyclical:
        :param price:
        :return:
        '''
        course = Course(course_name,cyclical,price,school_name)
        course.save()






class School(BaseClass):
    def __init__(self,name,address):
        self.name = name
        self.address =address
        self.course_name_list = []

    def save_course_name_list(self,course):
        self.course=course
        self.course_name_list.append(course)
        self.save()




class Course(BaseClass):
    def __init__(self,name,cyclical,price,school_name):
        self.name = name
        self.cyclical=cyclical
        self.price=price
        self.school_name=school_name
        self.student_name_list = []
        self.save()

    def add_student(self,student_name):
        self.student_name_list.append(student_name)
        self.save()



class Teacher(BaseClass):
    def __init__(self,name,password):
        self.name = name
        self.password = password
        self.school_list=[]
        self.course_list=[]
        self.save()


    def check_course(self):
        return self.course_list


    def teacher_select_course(self,course):
        self.course_list.append(course)
        self.save()

    def update_student_score(self,student,course_name,score):
        student.scores[course_name] =score
        student.save()






class Student(BaseClass):
    def __init__(self):
        self.school = None
        self.course_list = []
        self.scores = {}
        self.balance = 0



    def register(self,name,password):
        self.name = name
        self.password = password
        self.save()

    def select_school(self,school):
        self.school=school
        self.save()


    def student_select_course(self,course):
        self.course_list.append(course)
        self.scores[course]=0
        self.save()

    def pay_cost(self,balance):
        self.balance=balance
        self.save()









